#include <stdio.h>
#include <pocketsphinx.h>

int main(int argc, char *argv[]) {

    // create configuration
    cmd_ln_t * config =
            cmd_ln_init(NULL, ps_args(), TRUE,
                "-hmm", MODELDIR "/en-us/en-us",
                "-lm", MODELDIR "/en-us/en-us.lm.bin",
                "-dict", MODELDIR "/en-us/cmudict-en-us.dict",
                "-fwdtree", "yes",
                "-fwdflat", "yes",
                "-bestpath", "yes",
                "-mfclogdir", ".",
                "-rawlogdir", ".",
       		"-logfn", "/dev/null", // no logs in stdout
                "-samprate", "16000", NULL);


    // instantiate decoder
    ps_decoder_t *decoder = ps_init(config);

    // open file and parse it
    FILE *file = fopen("goforward.raw", "rb");
    // decode raw file
    int samples = ps_decode_raw(decoder, file, -1);
    fclose(file);

    // create hypothesis
    int32 score;

    char const *hypothesis = ps_get_hyp(decoder, &score);

    printf("Recognized: %s\n", hypothesis);

    ps_free(decoder);

    return 0;
}
